﻿using ProjectCloth.Entity;
using ProjectCloth.FrmUI.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProjectCloth.FrmUI.Users
{
    public partial class EditPwdFrm : Form
    {
        private ClothContext db = new ClothContext();
        public bool changePwd = false;
        public EditPwdFrm()
        {
            InitializeComponent();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            var userId = LoginInfo.GetLoginInfo().UserId;
            if (userId > 0)
            {
                var user = db.Users.Find(userId);
                if (user != null)
                {
                    if (user.Password == this.orgPwdTxt.Text && newPwdTxt.Text == rePwdTxt.Text && !string.IsNullOrEmpty(newPwdTxt.Text))
                    {
                        user.Password = newPwdTxt.Text;
                        if (db.SaveChanges() > 0)
                        {
                            //MessageBox.Show("修改成功！");
                            changePwd = true;
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("修改失败！");
                        }
                    }
                    else
                    {
                        MessageBox.Show("输入有误！");
                    }
                }
            }
        }
    }
}
